package com.oristartech.ori.common.generater;

public class Column {

    private String mysqlColumnName;
    private String mysqlColumnNameUpperCase;
    private String mysqlDataType;
    private String mysqlColumnComment;

    private String javaCamelName;
    private String javaPascalName;
    private String javaType;
    private String javaTypeImportPackage;

    public String getMysqlColumnName() {
        return mysqlColumnName;
    }

    public void setMysqlColumnName(String mysqlColumnName) {
        this.mysqlColumnName = mysqlColumnName;
        this.mysqlColumnNameUpperCase = mysqlColumnName.toUpperCase();
        this.javaCamelName = Table.setUnderlineToCamel(mysqlColumnName);
        this.javaPascalName = Table.setFirstLetterUpperCase(this.javaCamelName);
    }

    public String getMysqlColumnNameUpperCase() {
        return mysqlColumnNameUpperCase;
    }

    public void setMysqlColumnNameUpperCase(String mysqlColumnNameUpperCase) {
        this.mysqlColumnNameUpperCase = mysqlColumnNameUpperCase;
    }

    public String getMysqlDataType() {
        return mysqlDataType;
    }

    public void setMysqlDataType(String mysqlDataType) {
        buildJavaType(mysqlDataType);
    }

    public String getMysqlColumnComment() {
        return mysqlColumnComment;
    }

    public void setMysqlColumnComment(String mysqlColumnComment) {
        this.mysqlColumnComment = mysqlColumnComment;
    }

    public String getJavaCamelName() {
        return javaCamelName;
    }

    public void setJavaCamelName(String javaCamelName) {
        this.javaCamelName = javaCamelName;
    }

    public String getJavaPascalName() {
        return javaPascalName;
    }

    public void setJavaPascalName(String javaPascalName) {
        this.javaPascalName = javaPascalName;
    }

    public String getJavaType() {
        return javaType;
    }

    public void setJavaType(String javaType) {
        this.javaType = javaType;
    }

    public String getJavaTypeImportPackage() {
        return javaTypeImportPackage;
    }

    public void setJavaTypeImportPackage(String javaTypeImportPackage) {
        this.javaTypeImportPackage = javaTypeImportPackage;
    }

    private void buildJavaType(String columnType) {
        final String string = "String";
        this.mysqlDataType = columnType;
        switch (columnType) {
            case "BIGINT":
                this.javaType = "Long";
                break;
            case "BLOB":
            case "MEDIUMBLOB":
                this.javaType = "Blob";
                this.mysqlDataType = "BLOB";
                this.javaTypeImportPackage = "import java.sql.Blob;";
                break;
            case "TEXT":
            case "LONGTEXT":
                this.javaType = string;
                this.mysqlDataType = "LONGVARCHAR";
                break;
            case "CHAR":
            case "VARCHAR":
            case "LONGVARCHAR":
                this.javaType = string;
                break;
            case "DATE":
            case "DATETIME":
            case "TIMESTAMP":
                this.mysqlDataType = "TIMESTAMP";
                this.javaType = "Date";
                this.javaTypeImportPackage = "import java.util.Date;";
                break;
            case "INTEGER":
            case "TINYINT":
            case "SMALLINT":
                this.javaType = "Integer";
                break;
            case "INT":
                this.mysqlDataType = "INTEGER";
                this.javaType = "Integer";
                break;
            case "FLOAT":
            case "DOUBLE":
            case "NUMERIC":
            case "DECIMAL":
                this.javaType = "BigDecimal";
                this.javaTypeImportPackage = "import java.math.BigDecimal;";
                break;
            default:
                this.javaType = string;
        }
    }
}
